package com.it.dao;

import com.it.domain.AdminUsers;
import com.it.domain.Employee_salary;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AdminUsersDao {
    /**
     * 登录
     * @return
     */
    @Select("select * from users where username = #{username} and Password = #{Password}")
    List<AdminUsers> UserLogin(AdminUsers adminUsers);

    /**
     * 注册信息
     * @param adminUsers
     */
    @Insert("INSERT INTO users (NAME,username,Password,gender,phoneNum,Entry_date,wage,POSITION)\n" +
            "VALUES(#{name},#{username},#{Password},#{gender},#{phoneNum},#{Entry_date},#{wage},#{position})")
    void UserRegist(AdminUsers adminUsers);

    /**
     * 查询所有Users
     * @return
     */
    @Select("Select * from users")
    List<AdminUsers> FindAll ();

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Select("Select * from users where id=#{id}")
    List<AdminUsers> FindById(int id);

    /**
     * 根据id改变users
     * @param adminUsers
     */
    @Update("UPDATE users set name = #{name}, username = #{username}, password = #{password}, gender = #{gender}, phoneNum = #{phoneNum}" +
            ", Entry_date = #{Entry_date}, wage = #{wage}, position = #{position} WHERE id = #{id}")
    void changeById(AdminUsers adminUsers);

    /**
     * 根据id删除user
     * @param id
     */
    @Delete("delete from users where id = #{id}")
    void deleById(int id);

    /**
     * 模糊查询
     */
    @Select("SELECT * FROM users WHERE name LIKE concat('%',#{name},'%')")
    List<AdminUsers> findByName(String name);

    /**
     * 在salary插入信息
     *
     */
    @Insert("insert into Employee_salary (name,position,wage,reason,salary_date) VALUES(#{name},#{position},#{wage},#{reason},#{salary_date})")
    void insertSalary(Employee_salary employee_salary);

    /**
     * 所有发工资记录
     * @return
     */
    @Select("Select * from Employee_salary")
    List<Employee_salary> FindAllSalary();

    /**
     * 根据姓名模糊查询salary
     * @param name
     * @return
     */
    @Select("SELECT * FROM Employee_salary WHERE name LIKE concat('%',#{name},'%')")
    List<Employee_salary> FindAllSalaryByName(String name);
}
